<template>
  <view>
    <!-- #ifdef APP-PLUS -->
    <view class="status_bar"></view>
    <!-- #endif -->
    <!-- #ifndef MP-WEIXIN -->
    <my-navbar
      title="门店导航"
      leftText=""
      color="#000"
      leftIcon="false"
      background="white"
      style="z-index: 10000"
    ></my-navbar>
    <!-- #endif -->
    <!-- #ifdef MP-WEIXIN-->
    <my-storemap-wx v-show="mapDisplay" @getList="getList"></my-storemap-wx>
    <!-- #endif -->
    <!-- #ifdef APP-PLUS -->
    <my-storemap-app v-show="mapDisplay" @getList="getList"></my-storemap-app>
    <!-- #endif -->
    <!-- #ifndef MP-WEIXIN || APP-PLUS -->
    <my-storemap v-show="mapDisplay" @getList="getList"></my-storemap>
    <!-- #endif -->
    <view class="bgBox">
      <!-- 公司简介 -->
      <view class="blurb">
        <view class="blurb_title"> 简介 </view>
        <view class="blurb_content">
          {{ introduction }}
        </view>
      </view>
      <!-- 轮播图 -->
      <view class="banner">
        <swiper class="swiper" circular :autoplay="true">
          <swiper-item v-for="item in banner" :key="item.goods_id">
            <image class="img" :src="item" mode="scaleToFill"></image>
          </swiper-item>
        </swiper>
      </view>
    </view>
    <view class="info">
      <u-notice-bar
        mode="horizontal"
        :list="notice"
        type="none"
        :speed="100"
      ></u-notice-bar>
    </view>
    <view class="store">
      <view class="left">
        <view class="flex">
          <view class="button active">全部门店</view>
        </view>
      </view>
      <view class="right">
        <!-- <view class="retract" @click="changeMapDisplay">
          <u-icon :name="mapDisplay ? 'arrow-up' : 'arrow-down'"></u-icon>
          <span style="margin-left: 10rpx">{{
            mapDisplay ? "收起地图" : "展开地图"
          }}</span>
        </view> -->
        <view class="search" @click="toSearch">
          <image src="../../static/image/search.png"></image>
        </view>
      </view>
    </view>
    <!-- 门店 -->
    <view class="shop">
      <view v-if="list.length != 0">
        <view v-for="(item, index) in list" :key="index" @click="toStore(item)">
          <view class="shop-box">
            <!-- 商品主图 -->
            <view class="shop-box-img">
              <image
                :src="
                  'https://copartner.oss-cn-beijing.aliyuncs.com/' +
                  (item.company_details.site_logo ||
                    'logo/2403/12/kLg9LUmAwobI2y6DtO0HqXp9dXI7GUDGpYlYTPh8.png')
                "
              >
              </image>
            </view>
            <!-- 商品信息 -->
            <view class="shop-box-info">
              <text class="title one_ellipsis">{{
                item.company_details.company_name || "测试"
              }}</text>
              <view class="tip">
                <text class="tip-content one_ellipsis">{{
                  item.categorys || "暂无"
                }}</text>
                <text class="tip-sold"
                  >已售 {{ item.company_details.order_count || "0" }}</text
                >
              </view>
              <view class="seg"></view>
              <view class="condition">
                <view class="title time">
                  <text> 配送时间</text>
                  <text class="times"
                    >{{ item.company_details.open_time | timeFilter }}-{{
                      item.company_details.end_time | timeFilter
                    }}</text
                  >
                </view>
                <view class="title money"> 距离{{ item.distance }}km </view>
              </view>
              <view class="address">
                <text class="address-info one_ellipsis"
                  >地址：{{
                    item.company_details.company_address || "暂无"
                  }}</text
                >
                <view
                  class="iphone"
                  @click.stop="call(item.company_details.site_phone)"
                >
                  <image src="/static/image/iphone.png"></image>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
      <view v-if="isLoading" class="loading">
        <u-loading mode="circle"></u-loading> 正在加载...
      </view>
      <!-- 无门店 -->
      <view class="noshop" v-if="list.length == 0 && !isLoading">
        <image src="/static/image/sotre_nodata.png"></image>
      </view>
    </view>
  </view>
</template>

<script>
import { $https } from "@/static/js/request.js";
export default {
  data() {
    return {
      list: [], // 列表
      isLoading: true, // 加载
      mapDisplay: true, // 地图状态
      location: {}, // 当前位置信息
      banner: [], // 轮播图
      introduction: "", // 公司介绍
      notice: [], // 通知
    };
  },
  created() {
    this.getData();
  },
  filters: {
    timeFilter: function (value) {
      if (!value) return "暂无";
      return value.slice(0, 5);
    },
  },
  methods: {
    // 获取门店配置
    getData() {
      $https(
        "GETN",
        "getStoreinfo",
        {},
        (res) => {
          if (res.data.errcode == 0) {
            console.log(res);
            if (res.data.data.list.img_arr.length == 0) {
              this.banner = [
                "https://copartner.oss-cn-beijing.aliyuncs.com/logo/2403/15/qJtTwpJT5czNkOD6QNTaHOL5QWycHbJWdPmTQSRZ.jpeg",
              ];
            } else {
              this.banner = res.data.data.list.img_arr;
              this.introduction = res.data.data.list.introduction;
              this.notice.push(res.data.data.list.notice);
            }
          } else {
            uni.showToast({
              icon: "none",
              title: res.data.errmsg,
            });
          }
        },
        true
      );
    },
    // 获取列表
    getList(data) {
      this.list = data.list;
      this.location = data.location;
      this.isLoading = false;
    },
    // 地图显示/隐藏
    changeMapDisplay() {
      this.mapDisplay = !this.mapDisplay;
    },
    // 去搜索
    toSearch() {
      uni.navigateTo({
        url: "./searchGuide?location=" + JSON.stringify(this.location),
      });
    },
    // 去门店
    toStore(item) {
      // #ifdef MP-WEIXIN || APP-PLUS
      uni.navigateTo({
        url: "/subindex/webview/webview?url=" + item.domain_name,
      });
      // #endif
      // #ifndef MP-WEIXIN || APP-PLUS
      window.location.href = "https://test.caidj.net.cn/cmp#/?isGuide=true";
      // #endif
    },
  },
};
</script>

<style lang="scss">
.bgBox {
  width: 690rpx;
  margin: auto;
  background: #ffffff;
  padding-bottom: 20rpx;
  box-sizing: border-box;
}
.blurb {
  width: 690rpx;
  padding: 30rpx 20rpx;
  box-sizing: border-box;
  background: #ffffff;
  margin: 20rpx auto;
  &_title {
    font-size: 38rpx;
    font-weight: 700;
    text-align: center;
  }
  &_content {
    text-indent: 2em;
    font-size: 26rpx;
    margin-top: 10rpx;
    line-height: 1.5;
  }
}
.banner {
  // margin-top:30rpx;
  width: 650rpx;
  height: 320rpx;
  margin: auto;
  background: #ffffff;
  border-radius: 20rpx;
  .swiper {
    border-radius: 20rpx;
    overflow: hidden;
    height: 320rpx;
  }
  .img {
    width: 100%;
    height: 320rpx;
  }

  uni-swiper {
    height: 100%;
  }
}
.info {
  width: 670rpx;
  margin: 0 auto 10rpx;
}
.store {
  background: white;
  padding: 20rpx 30rpx;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left {
    .button {
      width: 150rpx;
      height: 50rpx;
      border-radius: 25rpx;
      background: #f5f5f5;
      font-size: 24rpx;
      line-height: 50rpx;
      text-align: center;
      margin-right: 20rpx;
    }
    .active {
      background: #40af37;
      color: #ffffff;
    }
  }
  .right {
    display: flex;
    align-items: center;
    .retract {
      font-size: 24rpx;
      color: #666666;
    }
    .search {
      width: 50rpx;
      height: 50rpx;
      margin-left: 20rpx;
      image {
        width: 100%;
        height: 100%;
      }
    }
  }
}
.shop {
  width: 100%;
  position: relative;
  .loading {
    margin: 20px auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  &-box {
    margin: 30rpx 30rpx 30rpx 30rpx;
    background-color: #ffffff;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 10rpx;
    border-radius: 10rpx;

    &-img {
      box-sizing: content-box;
      width: 180rpx;
      height: 180rpx;
      border-radius: 10rpx;
      padding: 20rpx;

      image {
        width: 100%;
        height: 100%;
      }
    }

    &-info {
      width: 430rpx;
      display: flex;
      flex-direction: column;
      justify-content: space-evenly;
      height: 192rpx;
      position: relative;

      .collect {
        position: absolute;
        bottom: 135rpx;
        right: -42rpx;
        width: 84rpx;
        height: 73rpx;
      }

      .title {
        width: 100%;
        font-size: 26rpx;
        font-weight: 600;
        color: #333;
      }

      .tip {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;

        &-content {
          font-size: 20rpx;
          font-weight: 400;
          color: #656565;
          width: 300rpx;
        }

        &-sold {
          width: 130rpx;
          font-size: 19rpx;
          font-weight: 400;
          color: #656565;
          white-space: nowrap;
          text-align: right;
        }
      }

      .seg {
        width: 100%;
        height: 1rpx;
        background-color: #e5e5e5;
      }

      .condition {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;

        .title {
          font-size: 20rpx;
          font-weight: 400;
          color: #656565;
          white-space: nowrap;
        }

        .time {
          padding-left: 14rpx;
          background-color: #fff5e7;
          min-width: 210rpx;
          width: 224rpx;
          height: 30rpx;
          line-height: 30rpx;
          position: relative;

          text {
            position: relative;
            top: 0rpx;
          }
        }

        .times {
          color: #d75131;
          margin-left: 10rpx;
        }

        .money {
          width: 160rpx;
          text-align: right;
        }

        .moneys {
          color: #d75131;
          margin-right: 10rpx;
        }
      }

      .address {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;

        &-info {
          width: 380rpx;
          font-size: 20rpx;
          font-weight: 400;
          color: #656565;
        }

        .iphone {
          width: 23rpx;
          height: 23rpx;
          display: flex;
          justify-content: center;
          align-items: center;

          image {
            width: 80%;
            height: 80%;
          }
        }
      }
    }
  }
}
.noshop {
  width: 580rpx;
  height: 360rpx;
  margin: 65rpx auto 0;
  image {
    width: 100%;
    height: 100%;
  }
}
</style>
